import axios from 'axios';

class Pay {

  //获取订单的支付信息
  static getPayStatus(orderIds, success, fail) {
    if (!orderIds) {
      fail({
        code: '1',
        msg: '缺少订单参数'
      });
      return;
    }
    axios.get('pay/status.json?orderNos=' + orderIds).then(function (res) {
      success(res.data);
    }).catch(fail);
  }

  //公司或余额支付
  static pay = function (data, success, fail) {
    axios.post('pay/mixedPay.json', data).then(res => {
      success(res.data);
    }).catch(fail);
  };

  //获取ping++支付对象
  static getPayCharge = function (params, success, fail) {
    params.openId = $tool.ss.getItem('openId') || null;
    axios.get('pay/getCharge.json', {
      params: params
    }).then(res => {
      success(res.data);
    }).catch(fail);
  };

  //根据支付计划号获取支付结果信息
  static getPayResult(params, success, fail) {
    axios.get('pay/getResult.json', {
      params: params
    }).then(function (res) {
      success(res.data);
    }).catch(fail);
  }

  //是否支付成功
  static validateStatus(planId, success, fail) {
    axios.get('pay/validState.json?planId=' + planId).then(function (res) {
      success(res.data);
    }).catch(fail);
  }
}

export default Pay;
